;(function () {
  var eDom = function (selector) {
    return new eDom.fn.Init(selector)
  }
  eDom.fn = eDom.prototype = {
    Init: function (selector, context) {
      if (!selector) return
      if (!context) context = document
      var maybeID = selector[0] === '#'
      var maybeClass = !maybeID && selector[0] === '.'
      var nameOnly = maybeID || maybeClass ? selector.slice(1) : selector
      var isSimple = /^[\w-]*$/.test(nameOnly)
      this.length = 1
      this.context = context
      this.selector = selector
      this[0] = selector
      if (isSimple && maybeID) {
        this[0] = context.getElementById(nameOnly) || null
        this._proto_ = eDom.fn
        return this
      } else {
        if (isSimple && !maybeID) {
          if (maybeClass && context.getElementsByClassName) {
            var tags1 = context.getElementsByClassName(nameOnly)
            this.length = tags1.length
            for (var i1 = 0, len1 = tags1.length; i1 < len1; i1++) {
              if (tags1[i1].className.indexOf(nameOnly) !== -1) {
                this[i1] = tags1[i1]
              }
            }
            return this
          } else if (maybeClass) {
            var tags2 = context.getElementsByTagName('*')
            this.length = tags2.length
            for (var i2 = 0, len2 = tags2.length; i2 < len2; i2++) {
              if (tags2[i2].className === nameOnly) {
                this[i2] = tags2[i2]
              }
            }
            return this
          } else {
            var tags3 = context.getElementsByTagName(nameOnly)
            this.length = tags3.length
            for (var i3 = 0, len3 = tags3.length; i3 < len3; i3++) {
              if (tags3[i3].className === nameOnly) {
                this[i3] = tags3[i3]
              }
            }
            return this
          }
        }
      }
    },
    closest: function (selector) {
      var el = this[0]
      var matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector
      var maybeID = selector[0] === '#'
      var maybeClass = !maybeID && selector[0] === '.'
      var nameOnly = maybeID || maybeClass ? selector.slice(1) : selector
      var isSimple = /^[\w-]*$/.test(nameOnly)
      if (maybeID && isSimple) {
        while (el) {
          if (el.nodeType === 9) {
            return []
          } else if (el.getAttribute('id') === nameOnly) {
            this[0] = el
            return this
          } else {
            el = el.parentNode
          }
        }
      } else if (maybeClass && isSimple) {
        while (el) {
          if (el.nodeType === 9) {
            return []
          } else if (el.classList.contains(nameOnly)) {
            this[0] = el
            return this
          } else {
            el = el.parentNode
          }
        }
      } else {
        while (el) {
          if (el.nodeType === 9) {
            return []
          } else if (matchesSelector.call(el, selector)) {
            this[0] = el
            return this
          } else {
            el = el.parentNode
          }
        }
      }
    },
    getCookies: function (name) {
      var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
      var matched = document.cookie.match(reg)
      if (matched) {
        return decodeURI(matched[2])
      } else {
        return null
      }
    },
    setCookies: function (name, value, seconds) {
      if (!seconds) {
        seconds = 1 * 24 * 3600000
      }
      var exp = new Date()
      exp.setTime(exp.getTime() + seconds)
      document.cookie = name + '=' + encodeURI(value) + ';expires=' + exp.toUTCString()
    },
    delCookies: function (name) {
      var exp = new Date()
      var oldCookies = this.getCookies(name)
      exp.setTime(exp.getTime() - 1)
      if (oldCookies) {
        document.cookie = name + '=' + oldCookies + ';expires=' + exp.toUTCString()
      }
    },
    addCookies: function (name, value, days) {
      if (!days) {
        days = 90
      }
      var exp = new Date()
      exp.setTime(exp.getTime() + days * 24 * 3600000)
      var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
      var matched = document.cookie.match(reg)
      if (matched) {
        var oldValue = matched[2]
        var newValue = oldValue + '&' + encodeURI(value)
        document.cookie = name + '=' + newValue + ';expires=' + exp.toUTCString()
      } else {
        this.setCookies(name, value, days)
      }
    },
    Mnews: function (msg, time) {
      time = time || 1000
      var root = document.getElementsByTagName('body')[0]
      var timer = null
      var tipsEle = document.createDocumentFragment()
      var div = document.createElement('div')
      var p = document.createElement('p')
      div.id = 'toolTipsContainer'
      p.className = 'anim-tips'
      p.innerText = msg
      div.setAttribute('style', 'position:fixed;left:0;bottom:25%;width:100%;text-align:center;')
      p.setAttribute('style', 'display:inline-block;padding:0.6em .9em;background:rgba(0,0,0,0.8);font-size:.5em;color:#fff;border-radius:0.3em;')
      div.appendChild(p)
      tipsEle.appendChild(div)
      root.appendChild(tipsEle)
      timer = setTimeout(function () {
        clearTimeout(timer)
        timer = null
        root.removeChild(div)
      }, time)
    },
    Mconfirm: function (obj) {
      var title = obj.title || '提示'
      var desc = obj.desc || ' '
      var bt1Text = obj.bt1Text || '取消'
      var bt2Text = obj.bt2Text || '确定'
      var isSingleBt = obj.isSingleBt || false
      var confirm = obj.confirmBt || null
      var cancel = obj.cancelBt || null
      var root = document.getElementsByTagName('body')[0]
      var old = document.getElementById('iosMessage')
      if (old) {
        return false
      }
      var element = document.createElement('div')
      element.setAttribute('class', 'ios-message')
      element.setAttribute('id', 'iosMessage')
      var container = document.createElement('div')
      container.setAttribute('class', 'container')
      container.innerHTML = '<div class="message-header"><h6>' + title + '</h6><p>' + desc + '</p></div>'
      var btCon = document.createElement('div')
      if (!isSingleBt) btCon.setAttribute('class', 'message-bt')
      else btCon.setAttribute('class', 'message-full-bt')
      var btCancel = document.createElement('p')
      btCancel.innerText = bt1Text
      var btConfirm = document.createElement('p')
      btConfirm.innerText = bt2Text
      if (!isSingleBt) btCon.appendChild(btCancel)
      btCon.appendChild(btConfirm)
      btConfirm.addEventListener('click', function () {
        if (confirm) {
          root.removeChild(element)
          confirm()
        } else {
          root.removeChild(element)
        }
        window.removeEventListener('hashchange', remove)
      })
      btCancel.addEventListener('click', function () {
        if (cancel) {
          root.removeChild(element)
          cancel()
        } else {
          root.removeChild(element)
        }
        window.removeEventListener('hashchange', remove)
      })
      container.appendChild(btCon)
      element.appendChild(container)
      root.appendChild(element)
      window.addEventListener('hashchange', remove)
      function remove () {
        root.removeChild(element)
        window.removeEventListener('hashchange', remove)
      }
    },
    checkNum: function (num) {
      let rule = /^(\d+)|((\.\d)?)$/g
      if (rule.test(num)) {
        return true
      }
      return false
    },
    checkPhone: function (phone) {
      let rule = /^1\d{10}$/g // 为了防止出现特殊情况,只验证位数
      if (rule.test(phone)) {
        return true
      }
      return false
    },
    checkIDCard: function (id) {
      let rule = /(^\d{15}$)|(^\d{17}(x|X|\d)$)/g
      if (rule.test(id)) {
        return true
      }
      return false
    },
    getUrlOption: function (name) {
      var reg = new RegExp('(^|&|/?)' + name + '=([^&]*)(&|$)', 'i')
      var r = location.href.match(reg)
      if (r) {
        return r[2]
      } else {
        return null
      }
    },
    preventDefault: function (event) {
      var e = event || window.event
      if (e.preventDefault) {
        e.preventDefault()
      } else {
        e.returnValue = false
      }
    },
    timeTransform: function (timestamp) {
      let date = new Date(timestamp * 1000)
      let dateStr = date.toLocaleDateString()
      let timeStr = date.toLocaleTimeString()
      dateStr = dateStr.replace(/\//g, '-')
      timeStr = timeStr.substring(2)
      return dateStr + ' ' + timeStr
    },
    arrDelNull: function (arr) {
      var len = arr.length
      var newArr = []
      for (var i = 0; i < len; i++) {
        if (arr[i]) {
          newArr.push(arr[i])
        }
      }
      return newArr
    }
  }
  eDom.fn.Init.prototype = eDom.fn
  if (typeof module !== 'undefined' && module.exports) {
    module.exports = eDom
  } else {
    window.Dom = eDom
    window.$ === undefined && (window.$ = eDom)
  }
}())